package tpdisenio2009.mvp.display;

import java.util.List;
import javax.swing.table.AbstractTableModel;
import tpdisenio2009.model.beans.SoccerMatch;

/**
 *
 * @author Nicolás Kreiff
 */
public class SoccerMatchTableModel extends AbstractTableModel {

    private final List<SoccerMatch> matchs;

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0: return "Partido";
            case 1: return "Local";
            case 2: return "Visitante";
            case 3: return "Estado (*)";
            default: return "";
        }
    }

    public SoccerMatchTableModel(List<SoccerMatch> matchs) {
        this.matchs = matchs;
    }

    public List<SoccerMatch> getMatchs() {
        return matchs;
    }

    public SoccerMatch getSoccerMatch(int row) {
        if (row < 0 || row >= matchs.size())
            return null;
        return matchs.get(row);
    }

    public int getRowCount() {
        return matchs == null? 0 : matchs.size();
    }

    public int getColumnCount() {
        return 4;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        try {
            SoccerMatch match = this.matchs.get(rowIndex);
            switch (columnIndex) {
                case 0:
                    return match.getId();
                case 1:
                    return match.getRealTeamLocal().getName();
                case 2:
                    return match.getRealTeamVisitor().getName();
                case 3:
                    return match.getState();
            }
        } catch (Exception e) {
        }
        return null;
    }
}
